import { get, post } from '../../utils/request'
const state = {
  // 用来保存查询出来的用户信息
  userRoles: [],
  total: 0
}

const actions = {
  // 分页查询所有用户信息
  findAllUserRoles(context, list) {
    // 异步操作
    get('/baseUser/pageQuery', list).then((res) => {
      let response = res.data.list
      context.commit('setUserRoles', response)
      let total = res.data.total
      context.commit('setTotal', total)
    })
  },
  // 保存用户信息
  saveUserRole(context, from) {
    let response = post('/baseUser/saveOrUpdate', from)
    return response
  },
  // 删除用户信息
  deleteUserRole(context, id) {
    let response = get('/baseUser/deleteById', id)
    return response
  }
}

const mutations = {
  // 修改state中的值
  setUserRoles(state, response) {
    state.userRoles = response
  },
  setTotal(state, total) {
    state.total = total
  }
}

export default {
  namespaced: true,
  state,
  actions,
  mutations
}
